
import { useLaunch } from '@tarojs/taro'
import { useState } from 'react'
import Taro from '@tarojs/taro'
import './app.scss'
import { getOpenId,wxLogin } from './services/api'
import { View } from '@tarojs/components'

function App({ children }) {
  const [isLogin,setIsLogin] = useState(false)

  useLaunch(async () => {
    const res = await Taro.login()
    const openIdRes = await getOpenId(res.code)
    const openId = openIdRes.result.openId
    const loginRes = await wxLogin(openId)
    const {accessToken,avatar,city,country,language,mobile,nickName,provice,sex,userId} = loginRes.result
    Taro.setStorageSync("Authorization", accessToken);
    const user = {...loginRes.result,openId}
    Taro.setStorageSync("user",user)
    setIsLogin(true)
  })

  // children 是将要会渲染的页面
  return children
}

export default App
